package com.risk.ctrl.exceptions;


import com.risk.ctrl.enums.ErrorCodeEnum;
import com.risk.ctrl.utils.StringBulidUtils;
import lombok.Data;


@Data
public class BusinessException extends RuntimeException {
    /**
     * 异常信息
     */
    private String errorMsg;

    /**
     * 异常编码
     */
    private String errorCode;

    public BusinessException(String errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    @Override
    public Throwable fillInStackTrace() {
        return this;
    }

    public BusinessException(ErrorCodeEnum errorCodeEnum) {
        this(errorCodeEnum.getCode(), errorCodeEnum.getDesc());
    }

    public BusinessException(ErrorCodeEnum errorCodeEnum, Throwable e) {
        super(errorCodeEnum.getDesc(), e);
        this.errorCode = errorCodeEnum.getCode();
        this.errorMsg = errorCodeEnum.getDesc();
    }

    public BusinessException(ErrorCodeEnum errorCodeEnum, Throwable e, Object... args) {
        super(errorCodeEnum.getDesc(), e);
        this.errorCode = errorCodeEnum.getCode();
        this.errorMsg = StringBulidUtils.replaceAllBrace(errorCodeEnum.getDesc(), args);
    }

    public BusinessException(ErrorCodeEnum errorCodeEnum, Object... args) {
        this(errorCodeEnum.getCode(), StringBulidUtils.replaceAllBrace(errorCodeEnum.getDesc(), args));
    }
}
